package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try (
                Connection con=DBUtil.getConnection();
                ){
            Statement stm=con.createStatement();
            String sql="SELECT COUNT(*) count \n" +
                    "FROM class c \n" +
                    "JOIN student s ON c.id = s.class_id \n" +
                    "WHERE c.name = '1年级1班'";
            ResultSet rs=stm.executeQuery(sql);
            if (rs.next()) {
                int count=rs.getInt("count");
                System.out.println("共计"+count+"人");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
